#include "key.h"

void key_init(void)
{
    IOMUXC_SetPinMux(IOMUXC_UART1_CTS_B_GPIO1_IO18, 0);
    IOMUXC_SetPinConfig(IOMUXC_UART1_CTS_B_GPIO1_IO18, 0xF080);
    gpio_config_type gpio_config;
    gpio_config.direction = gpio_input;
    gpio_init(GPIO1, 18, &gpio_config);
}

uint8_t key_getvalue(void)
{
    uint8_t ret = key_none;
    static uint8_t release = 1;
    if((release == 1) && (gpio_pin_read(GPIO1, 18) == 0))
    {
        delay(10);
        release = 0;
        if(gpio_pin_read(GPIO1, 18) == 0)
        {
            ret = key0_down;
        }
    }
    else if(gpio_pin_read(GPIO1, 18) == 1)
    {
        release = 1;
        ret = key_none;
    }
    return ret;
}